package com.weishi;

import com.weishi.tcp.ThreadSocket;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Logger;

public class TCPService {

    Logger logger = Logger.getLogger("TcpService");

    /**
     * 启动tcp服务监听接受消息
     */
    public void rum() {
        ServerSocket server = null;
        try{
            server = new ServerSocket(3000);
            logger.info("tcp service start！");
            Socket sock = null;
            while(true){
                sock = server.accept();
                sock.setSoTimeout(12000);
                logger.info(sock.getInetAddress().getHostAddress()+ " hello ……");
                ThreadSocket tsock = new ThreadSocket(sock);
                new Thread(tsock).start();
            }

        }catch(IOException e){
            e.printStackTrace();
        }
    }
}
